package com.yuncheng.oaApi.FlowController;



import com.yuncheng.exception.BusinessException;
import com.yuncheng.oaApi.FlowService.NewNkyssbFlowService;
import com.yuncheng.oaApi.busService.EditYssbService;
import com.yuncheng.oaApi.busService.MyLcFlowService;
import com.yuncheng.oaApi.busService.YssbService;
import com.yuncheng.oaApi.constant.OaCommonFlowConstant;
import com.yuncheng.oaApi.constant.OaFlowConstant;
import com.yuncheng.oaApi.entity.*;
import com.yuncheng.oaApi.mapper.NkBmysxmsbsplcFlowMapper;
import com.yuncheng.oaApi.service.*;
import com.yuncheng.oaApi.vo.*;
import com.yuncheng.spcyApi.service.ISpcyLogService;
import com.yuncheng.spcyApi.utils.DateConvert;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.annotation.AutoLog;

import com.yuncheng.oaApi.constant.NkConstant;

import com.yuncheng.oaApi.mapper.OaSysRoleMapper;
import com.yuncheng.oaApi.utils.GetUuIdUtils;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.utils.ThreadContextHelper;
import com.yuncheng.vo.CurrentUserVo;
import com.yuncheng.vo.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import utils.DateConversionUtils;
import utils.LogUtils;
import utils.ObjectToMapUtils;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

@Api(tags = "NEW_预算申报")
@RestController
@RequestMapping("/api/spzx-oa/yssb")
public class NewNkyssbFlowController {

    private static final Logger log = LoggerFactory.getLogger(NewNkyssbFlowController.class);
    @Resource
    @Lazy
    private INkBmysxmsbsplcService nkyssbbsplcService;

    @Resource
    private IOaSpcySqsxJobService oaSpcySqsxJobService;

    @Resource
    @Lazy
    private MyLcFlowService myLcFlowService;

    @Resource
    @Lazy
    private NkBmysxmsbsplcFlowMapper nkyssbbsplcFlowMapper;


    @Resource
    @Lazy
    private INkRsBmysxmsbService nkyrsBmysxmsbService;



    @Resource
    @Lazy
    private INkYssbhjService nkYssbhjService;

    @Resource
    @Lazy
    private IOaSysRoleService oaSysRoleService;

    @Resource
    @Lazy
    private OaSysRoleMapper oaSysRoleMapper;

    @Resource
    @Lazy
    private NewNkyssbFlowService nkyssbFlowService;

    @Resource
    @Lazy
    private INkYssbhyjlService nkYssbhyjlService;


    @Resource
    @Lazy
    private IOaProcessBusinessService oaProcessBusinessService;


    @Resource
    @Lazy
    private IOaSysTzMessageService oaSysTzMessageService;

    @Resource
    @Lazy
    private ISpcyLogService spcyLogService;

    @Resource
    @Lazy
    private INkYssbhjKtService nkYssbhjKtService;

    @Resource
    @Lazy
    private INkYssbhjysService nkYssbhjysServic;
    @Resource
    @Lazy
    private INkYssbhjPxService nkYssbhjpxService;


    @Resource
    @Lazy
    private INkYssbhjjxzbService nkYssbhjjxzbService;

    @Resource
    @Lazy
    private YssbService yssbService;


    @Resource
    @Lazy
    private EditYssbService editYssbService;

    @Resource
    @Lazy
    private INkRsNdService nkRsNdService;



    /**
     * 进入二上前判断
     */
    @AutoLog(value = "进入二上前判断")
    @ApiOperation(value = "进入二上前判断")
    @GetMapping(value = "/esList")
    public HttpResult esList(String jhid){
       if (StringUtils.isNotBlank(jhid)){
           List<OaJobEntity> jobEntities = oaSpcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                   .eq(OaJobEntity::getFpid, jhid)
                   .eq(OaJobEntity::getFhjmc, OaFlowConstant.YSSBLC_CWSH_ES));
            if (CollectionUtils.isNotEmpty(jobEntities)){
                //查询 jobEntities 列表中是否有环节名称为 财务审核(二上) 的环节 为已办或者待办
             return HttpResult.ok(true);

            }
        }
        return HttpResult.ok(false);
    }




    /**
     * 查询当前计划id 以及当前环节
     */
    @AutoLog(value = "查询当前计划id 以及当前环节")
    @ApiOperation(value = "查询当前计划id 以及当前环节")
    @GetMapping(value = "/getjhid")
    public HttpResult getjhid(){
        String fhjmc = "";
        String id = "";
        String fnd = "";
        List<NkRsnd> nkRsnds = nkRsNdService.list(new LambdaQueryWrapper<NkRsnd>()
                .eq(NkRsnd::getFsfxz, OaCommonFlowConstant.NDXZ_YES));
        int ndi = Integer.valueOf(nkRsnds.get(0).getFnd()) + 1;

        fnd = String.valueOf(ndi);


        List<NkBmysxmsbsplc> nkBmysxmsbsplcs = nkyssbbsplcService.list(new LambdaQueryWrapper<NkBmysxmsbsplc>()
                .eq(NkBmysxmsbsplc::getFnd, fnd));
        if (CollectionUtils.isNotEmpty(nkBmysxmsbsplcs)){
             id = nkBmysxmsbsplcs.get(0).getId();
            List<OaJobEntity> jobEntities = oaSpcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                    .eq(OaJobEntity::getFpid, id));
            if (CollectionUtils.isNotEmpty(jobEntities)){
                List<OaJobEntity> jobEntitiess = oaSpcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                        .eq(OaJobEntity::getFpid, id)
                        .eq(OaJobEntity::getFblzt, OaCommonFlowConstant.BLZT_DB));
                //如果待办不为空
                if (CollectionUtils.isNotEmpty(jobEntitiess)){
                    fhjmc = jobEntitiess.get(0).getFhjmc();
                }else {
                    fhjmc = OaFlowConstant.YSSBLC_ZXZRSH_ES;
                }

            }else {
                fhjmc = OaFlowConstant.YSSBLC_CWSH_YS;
            }
        }

        HashMap map = new HashMap<>();

        map.put("jhid", id);
        map.put("hjmc",fhjmc);
        return HttpResult.ok(map);

    }



    /**
     * 获取当前计划的所有部门预算申报环节
     */
    @AutoLog(value = "获取各部门的当前部门预算申报环节")
    @ApiOperation(value = "获取各部门的当前部门预算申报环节")
    @GetMapping(value = "/getBmyssblc")
    public HttpResult getBmyssblc(String jhid){
        List bmyssblc = yssbService.getBmyssblc(jhid);
        return HttpResult.ok(bmyssblc);
    }

    /**
     * 新建申报流程计划
     */
    @AutoLog(value = "新建申报计划")
    @ApiOperation(value = "新建申报计划")
    @PostMapping(value = "/add")
    public HttpResult addYssb(@RequestBody NkBmysxmsbsplc nkyssbbsplc){
        if (StringUtils.isBlank(nkyssbbsplc.getFjhmc())){
            throw new RuntimeException("请输入计划名称");
        }

        if (StringUtils.isBlank(nkyssbbsplc.getFjhzt())){
            throw new RuntimeException("请制定计划状态");
        }

        LocalDate currentDate = LocalDate.now().plusYears(1);


        String id = GetUuIdUtils.ReplaceUuId();

        nkyssbbsplc.setId(id);
//        nkyssbbsplc.setFnd(DateConversionUtils.DateToYear(new Date()));
        //下一年的申报流程
        nkyssbbsplc.setFnd(String.valueOf(currentDate.getYear()));
        nkyssbbsplc.setFjhsj(DateConversionUtils.DateToYMDMM(new Date()));
        nkyssbbsplcService.save(nkyssbbsplc);

        //新建申报计划的时候，自动生成所有科室的预算申报计划
        List<String> bmList = OaCommonFlowConstant.allBmList();
        for (String bm:bmList) {
            NkRsBmysxmsb nkRsBmysxmsb = new NkRsBmysxmsb();
            nkRsBmysxmsb.setId(GetUuIdUtils.ReplaceUuId());
            nkRsBmysxmsb.setFjhid(id);
            nkRsBmysxmsb.setFsqks(bm);
            nkyrsBmysxmsbService.save(nkRsBmysxmsb);
        }

        return HttpResult.ok("新增成功");
    }

    /**
     * 申报计划列表
     */
    @AutoLog(value = "申报计划列表")
    @ApiOperation(value = "申报计划列表")
    @GetMapping("list")
    public HttpResult list(NkBmysxmsbsplc nkyssbbsplc,
                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){


        List<NkRsnd> nkRsnds = nkRsNdService.list(new LambdaQueryWrapper<NkRsnd>()
                .eq(NkRsnd::getFsfxz, OaCommonFlowConstant.NDXZ_YES));

        int ndi = Integer.valueOf(nkRsnds.get(0).getFnd()) + 1;


        String nd = String.valueOf(ndi);


        LambdaQueryWrapper<NkBmysxmsbsplc> queryWrapper = new LambdaQueryWrapper<>();
        //计划名称
        queryWrapper.like(StringUtils.isNotBlank(nkyssbbsplc.getFjhmc()),NkBmysxmsbsplc::getFjhmc,nkyssbbsplc.getFjhmc());
        //计划时间
        queryWrapper.like(StringUtils.isNotBlank(nkyssbbsplc.getFjhsj()),NkBmysxmsbsplc::getFjhsj,nkyssbbsplc.getFjhsj());
        //计划状态
        queryWrapper.like(StringUtils.isNotBlank(nkyssbbsplc.getFjhzt()),NkBmysxmsbsplc::getFjhzt,nkyssbbsplc.getFjhzt());

        //年度
        queryWrapper.eq(NkBmysxmsbsplc::getFnd,nd);

        Page<NkBmysxmsbsplc> page = new Page<>(pageNo, pageSize);

        IPage<NkBmysxmsbsplc> pageList = nkyssbbsplcService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }




    /**
     * 编辑
     *
     * @param nkBmysxmsbsplc
     * @return
     */
    @AutoLog(value = "内控-预算申报-编辑")
    @ApiOperation(value = "内控-预算申报-编辑")
    //@RequiresPermissions("yssb:NkBmysxmsbsplc:edit")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody NkBmysxmsbsplc nkBmysxmsbsplc) {
        nkyssbbsplcService.updateById(nkBmysxmsbsplc);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "内控-预算申报-通过id删除")
    @ApiOperation(value = "内控-预算申报-通过id删除")
    //@RequiresPermissions("yssb:NkBmysxmsbsplc:delete")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam("id") String id) {
        nkyssbbsplcService.removeById(id);
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 查看科室预算申报
     */
    @AutoLog(value = "查看科室预算申报")
    @ApiOperation(value = "查看科室预算申报")
    @GetMapping(value = "/checkKsyssb")
    public HttpResult<?> checkKsyssb(String jhid) {
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();

        //查询当前角色是否是财务，如果是财务返回当前计划下所有的数据  如果不是财务，返回当前科室的数据。如果当前科室没有初始化一个
        List<OaSysRole> oaSysRoles = oaSysRoleService.list(new LambdaQueryWrapper<OaSysRole>()
                .eq(OaSysRole::getRoleName, NkConstant.ROLE_NAME_CW));


        List list = new ArrayList();

        if (CollectionUtils.isNotEmpty(oaSysRoles)) {

            List<OaSysUserRole> CWlist = oaSysRoleMapper.cwList();

            if (CollectionUtils.isNotEmpty(CWlist)) {
                //循环这个list
                for (OaSysUserRole cw : CWlist) {
                    list.add(cw.getUserId());
                }
                boolean exists = list.contains(currentUser.getId());

                if (exists){
                    List<NkRsBmysxmsb> nkRsBmysxmsbs = nkyrsBmysxmsbService.list(new LambdaQueryWrapper<NkRsBmysxmsb>()
                            .eq(NkRsBmysxmsb::getFjhid, jhid));
                    if (CollectionUtils.isEmpty(nkRsBmysxmsbs)){
                        return HttpResult.ok(nkRsBmysxmsbs);
                    }
                    return HttpResult.ok(nkRsBmysxmsbs);
                }else {

                    List<NkRsBmysxmsb> nkRsBmysxmsbs = nkyrsBmysxmsbService.list(new LambdaQueryWrapper<NkRsBmysxmsb>()
                            .eq(NkRsBmysxmsb::getFjhid, jhid)
                            .eq(NkRsBmysxmsb::getFsqks, currentUser.getOrgName()));
                    if (CollectionUtils.isEmpty(nkRsBmysxmsbs)){
                        NkRsBmysxmsb nkRsBmysxmsb = new NkRsBmysxmsb();
                        nkRsBmysxmsb.setFjhid(jhid);
                        nkRsBmysxmsb.setId(GetUuIdUtils.ReplaceUuId());
                        nkRsBmysxmsb.setTbrid(currentUser.getId());
                        nkRsBmysxmsb.setTbrxm(currentUser.getName());
                        nkRsBmysxmsb.setFsqks(currentUser.getOrgName());
                        nkRsBmysxmsb.setFsqsj(DateConversionUtils.DateToYMDMM(new Date()));
                        nkyrsBmysxmsbService.save(nkRsBmysxmsb);

                        return HttpResult.ok(nkRsBmysxmsb);
                    }else {

                        NkRsBmysxmsb bmysxmsb = nkyrsBmysxmsbService.getById(nkRsBmysxmsbs.get(0).getId());
                        if (StringUtils.isBlank(bmysxmsb.getTbrid())){
                            bmysxmsb.setTbrid(currentUser.getId());
                        }
                        if (StringUtils.isBlank(bmysxmsb.getTbrxm())){
                            bmysxmsb.setTbrxm(currentUser.getName());
                        }
                        if (StringUtils.isBlank(bmysxmsb.getFsqsj())){
                            bmysxmsb.setFsqsj(DateConversionUtils.DateToYMDMM(new Date()));
                        }
                        nkyrsBmysxmsbService.updateById(bmysxmsb);
                        return HttpResult.ok(nkRsBmysxmsbs);
                    }
                }
            }
        }
        return HttpResult.ok();
    }

    /**
     * 判断当前角色是否是财务
     */
    @AutoLog(value = "判断当前角色是否是财务")
    @ApiOperation(value = "判断当前角色是否是财务")
    @GetMapping(value = "/sfcw")
    public HttpResult<?> sfcw(){
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();

        //查询当前角色是否是财务，如果是财务返回当前计划下所有的数据  如果不是财务，返回当前科室的数据。如果当前科室没有初始化一个
        List<OaSysRole> sysRoles = oaSysRoleService.list(new LambdaQueryWrapper<OaSysRole>()
                .eq(OaSysRole::getRoleName, NkConstant.ROLE_NAME_CW));


        List list = new ArrayList();

        if (CollectionUtils.isNotEmpty(sysRoles)) {

            List<OaSysUserRole> CWlist = oaSysRoleMapper.cwList();

            if (CollectionUtils.isNotEmpty(CWlist)) {
                //循环这个list
                for (OaSysUserRole cw : CWlist) {
                    list.add(cw.getUserId());
                }
                boolean exists = list.contains(currentUser.getId());

                if (exists){
                    return HttpResult.ok(true);
                }else {
                    return HttpResult.ok(false);
                }
            }

        }

        return HttpResult.ok(false);
    }



    /**
     * 判断当前角色是否是出纳
     */
    @AutoLog(value = "判断当前角色是否是出纳")
    @ApiOperation(value = "判断当前角色是否是出纳")
    @GetMapping(value = "/sfcn")
    public HttpResult<?> sfcn(){
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();

        //查询当前角色是否是财务，如果是财务返回当前计划下所有的数据  如果不是财务，返回当前科室的数据。如果当前科室没有初始化一个
        List<OaSysRole> sysRoles = oaSysRoleService.list(new LambdaQueryWrapper<OaSysRole>()
                .eq(OaSysRole::getRoleName, NkConstant.ROLE_NAME_CN));


        List list = new ArrayList();

        if (CollectionUtils.isNotEmpty(sysRoles)) {

            List<OaSysUserRole> CNlist = oaSysRoleMapper.cnList();

            if (CollectionUtils.isNotEmpty(CNlist)) {
                //循环这个list
                for (OaSysUserRole cw : CNlist) {
                    list.add(cw.getUserId());
                }
                boolean exists = list.contains(currentUser.getId());

                if (exists){
                    return HttpResult.ok(true);
                }else {
                    return HttpResult.ok(false);
                }
            }

        }

        return HttpResult.ok(false);
    }

    /**
     * 部门预算申报表单-汇总
     */
    @AutoLog(value = "部门预算申报表单-汇总-差旅劳务")
    @ApiOperation(value = "部门预算申报表单-汇总-差旅劳务")
    @GetMapping(value = "/hzbd")
    public HttpResult<?> hzbd(String flx,String bm){
        List hzbd = yssbService.hzbd(flx,bm);
        return HttpResult.ok(hzbd);
    }

    /**
     *部门预算申报表单-汇总-课题
     */
    @AutoLog(value = "部门预算申报表单-汇总-课题")
    @ApiOperation(value = "部门预算申报表单-汇总-课题")
    @GetMapping(value = "/kthzbd")
    public HttpResult<?> kthzbd(String flx,String bm){
        List getyssbkt = yssbService.getyssbkt(flx,bm);
        return HttpResult.ok(getyssbkt);
    }


    /**
     *部门预算申报表单-汇总-印刷
     */
    @AutoLog(value = "部门预算申报表单-汇总-印刷")
    @ApiOperation(value = "部门预算申报表单-汇总-印刷")
    @GetMapping(value = "/yshzbd")
    public HttpResult<?> yshzbd(String flx,String bm){
        List getyssbkt = yssbService.getyssbys(flx,bm);
        return HttpResult.ok(getyssbkt);
    }


    /**
     *部门预算申报表单-汇总-培训
     */
    @AutoLog(value = "部门预算申报表单-汇总-培训")
    @ApiOperation(value = "部门预算申报表单-汇总-培训")
    @GetMapping(value = "/pxhzbd")
    public HttpResult<?> pxhzbd(String flx,String bm){
        List getyssbkt = yssbService.getyssbpx(flx,bm);
        return HttpResult.ok(getyssbkt);
    }

    /**
     * 绩效申报计算-汇总
     */
    @AutoLog(value = "绩效申报计算-汇总")
    @ApiOperation(value = "绩效申报计算-汇总")
    @GetMapping(value = "/hzjxzbss")
    public HttpResult<?> hzjxzbss(String flx,String bm){
        List getyssbkt = editYssbService.getyssbjxzb(flx,bm);
        return HttpResult.ok(getyssbkt);
    }

    /**
     * 部门预算申报计算
     */
    @AutoLog(value = "部门预算申报计算")
    @ApiOperation(value = "部门预算申报计算")
    @GetMapping(value = "/firstJs")
    public HttpResult<?> firstJs(String jhid,String jclx){
        List  list = nkyssbFlowService.firstJs(jhid,jclx);
        return HttpResult.ok(list);
    }



    /**
     * 部门预算申报计算
     */
    @AutoLog(value = "部门单独预算申报计算")
    @ApiOperation(value = "部门单独预算申报计算")
    @GetMapping(value = "/firstBmJs")
    public HttpResult<?> firstBmJs(String fjhid,String jclx,String bm){
        List list = nkyssbFlowService.firstJs(fjhid,jclx,bm);
        return HttpResult.ok(list);
    }




    /**
     * 编辑
     */
    @AutoLog(value = "编辑预算合计表")
    @ApiOperation(value = "编辑预算合计表")
    @PostMapping(value = "/editYs")
    public HttpResult<?> editYs(@RequestBody NkYssbhj nkYssbhjs){
        List list = new ArrayList();

        if (StringUtils.isNotBlank(nkYssbhjs.getId())) {

            NkYssbhj oldnkYssbhj = nkYssbhjService.getById(nkYssbhjs.getId());
            NkYssbhyjl nkYssbhyjl = new NkYssbhyjl();
            nkYssbhyjl.setId(GetUuIdUtils.ReplaceUuId());
            if (StringUtils.isNotBlank(nkYssbhjs.getFlx())){
                nkYssbhyjl.setFlx(nkYssbhjs.getFlx());
            }else {
                throw new BusinessException("类型为空");
            }

            nkYssbhyjl.setFxgsj(DateConversionUtils.DateToYMDMM(new Date()));
            nkYssbhyjl.setFxgr(ThreadContextHelper.getCurrentUser().getName());
            nkYssbhyjl.setFxgrid(ThreadContextHelper.getCurrentUser().getId());
            nkYssbhyjl.setFxgrbm(ThreadContextHelper.getCurrentUser().getOrgName());
            nkYssbhyjl.setFsfbc(OaCommonFlowConstant.NO);
            nkYssbhyjl.setFyssbjhid(nkYssbhjs.getFyssbjhid());
            nkYssbhyjl.setFyssbhjid(nkYssbhjs.getId());
            //先判断传过来的字段
            if (StringUtils.isNotBlank(nkYssbhjs.getFclbzqyszs())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhj.getFclbzqyszs());
                nkYssbhyjl.setFnewvalue(nkYssbhjs.getFclbzqyszs());
                nkYssbhyjl.setFxgjl("修改" + oldnkYssbhj.getFksy() + ":" + oldnkYssbhj.getFxmmc()
                        + "企业数/组数" + oldnkYssbhj.getFclbzqyszs() + "为" + nkYssbhjs.getFclbzqyszs());
            }
            if (StringUtils.isNotBlank(nkYssbhjs.getFclbzrs())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhj.getFclbzrs());
                nkYssbhyjl.setFnewvalue(nkYssbhjs.getFclbzrs());
                nkYssbhyjl.setFxgjl("修改" + oldnkYssbhj.getFksy() + ":" + oldnkYssbhj.getFxmmc()
                        + "差旅补助人数" + oldnkYssbhj.getFclbzrs() + "为" + nkYssbhjs.getFclbzrs());
            }
            if (StringUtils.isNotBlank(nkYssbhjs.getFclbzts())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhj.getFclbzts());
                nkYssbhyjl.setFnewvalue(nkYssbhjs.getFclbzts());
                nkYssbhyjl.setFxgjl("修改" + oldnkYssbhj.getFksy() + ":" + oldnkYssbhj.getFxmmc()
                        + "差旅补助天数" + oldnkYssbhj.getFclbzts() + "为" + nkYssbhjs.getFclbzts());
            }
            if (StringUtils.isNotBlank(nkYssbhjs.getFzxfts())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhj.getFzxfts());
                nkYssbhyjl.setFnewvalue(nkYssbhjs.getFzxfts());
                nkYssbhyjl.setFxgjl("修改" + oldnkYssbhj.getFksy() + ":" + oldnkYssbhj.getFxmmc()
                        + "住宿天数" + oldnkYssbhj.getFzxfts() + "为" + nkYssbhjs.getFzxfts());
            }
            if (StringUtils.isNotBlank(nkYssbhjs.getFjtfts())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhj.getFjtfts());
                nkYssbhyjl.setFnewvalue(nkYssbhjs.getFjtfts());
                nkYssbhyjl.setFxgjl("修改" + oldnkYssbhj.getFksy() + ":" + oldnkYssbhj.getFxmmc()
                        + "交通天数" + oldnkYssbhj.getFjtfts() + "为" + nkYssbhjs.getFjtfts());
            }
            if (StringUtils.isNotBlank(nkYssbhjs.getFlwfjcts())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhj.getFlwfjcts());
                nkYssbhyjl.setFnewvalue(nkYssbhjs.getFlwfjcts());
                nkYssbhyjl.setFxgjl("修改" + oldnkYssbhj.getFksy() + ":" + oldnkYssbhj.getFxmmc()
                        + "劳务费检查天数" + oldnkYssbhj.getFlwfjcts() + "为" + nkYssbhjs.getFlwfjcts());
            }
            if (StringUtils.isNotBlank(nkYssbhjs.getFlwfrc())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhj.getFlwfrc());
                nkYssbhyjl.setFnewvalue(nkYssbhjs.getFlwfrc());
                nkYssbhyjl.setFxgjl("修改" + oldnkYssbhj.getFksy() + ":" + oldnkYssbhj.getFxmmc()
                        + "劳务费人次" + oldnkYssbhj.getFlwfrc() + "为" + nkYssbhjs.getFlwfrc());
            }
            nkYssbhyjlService.save(nkYssbhyjl);

            if (nkYssbhjs.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
                list = yssbService.editYs(nkYssbhjs);
            }


            if (nkYssbhjs.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_ES)){
                list = yssbService.editEs(nkYssbhjs);
            }


        }else {
            if (nkYssbhjs.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
                list = yssbService.editYss(nkYssbhjs);
            }
            if (nkYssbhjs.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_ES)){
                list = yssbService.editEss(nkYssbhjs);
            }

        }
        return HttpResult.ok(list);
    }


    /**
     * 编辑-课题
     */
    @AutoLog(value = "编辑合计课题")
    @ApiOperation(value = "编辑合计课题")
    @PostMapping(value = "/editYskt")
    public HttpResult<?> editYskt(@RequestBody NkYssbhjKt nkYssbhjKt){
        List list = new ArrayList();

        if (StringUtils.isNotBlank(nkYssbhjKt.getId())) {

            NkYssbhjKt oldnkYssbhjKt = nkYssbhjKtService.getById(nkYssbhjKt.getId());
            NkYssbhyjl nkYssbhyjl = new NkYssbhyjl();
            nkYssbhyjl.setId(GetUuIdUtils.ReplaceUuId());
            if (StringUtils.isNotBlank(nkYssbhjKt.getFlx())){
                nkYssbhyjl.setFlx(nkYssbhjKt.getFlx());
            }else {
                throw new BusinessException("类型为空");
            }

            nkYssbhyjl.setFxgsj(DateConversionUtils.DateToYMDMM(new Date()));
            nkYssbhyjl.setFxgr(ThreadContextHelper.getCurrentUser().getName());
            nkYssbhyjl.setFxgrid(ThreadContextHelper.getCurrentUser().getId());
            nkYssbhyjl.setFxgrbm(ThreadContextHelper.getCurrentUser().getOrgName());
            nkYssbhyjl.setFsfbc(OaCommonFlowConstant.NO);
            nkYssbhyjl.setFyssbjhid(nkYssbhjKt.getFyssbjhid());
            nkYssbhyjl.setFyssbhjid(nkYssbhjKt.getId());
            //先判断传过来的字段
            if (StringUtils.isNotBlank(nkYssbhjKt.getFktmc())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjKt.getFktmc());
                nkYssbhyjl.setFnewvalue(nkYssbhjKt.getFktmc());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjKt.getFktfzks()+"课题名称:"+ oldnkYssbhjKt.getFktmc()
                        + "为:" + nkYssbhjKt.getFktmc());
            }
            if (StringUtils.isNotBlank(nkYssbhjKt.getFktjf())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjKt.getFktjf());
                nkYssbhyjl.setFnewvalue(nkYssbhjKt.getFktjf());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjKt.getFktfzks()+"课题经费:"+ oldnkYssbhjKt.getFktjf()
                        + "为:" + nkYssbhjKt.getFktjf());
            }
            if (StringUtils.isNotBlank(nkYssbhjKt.getFktwtdw())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjKt.getFktwtdw());
                nkYssbhyjl.setFnewvalue(nkYssbhjKt.getFktwtdw());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjKt.getFktfzks()+"课题委托单位/公司:"+ oldnkYssbhjKt.getFktjf()
                        + "为:" + nkYssbhjKt.getFktjf());
            }
            nkYssbhyjlService.save(nkYssbhyjl);

            if (nkYssbhjKt.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
                list = editYssbService.editYskt(nkYssbhjKt);
            }


            if (nkYssbhjKt.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_ES)){
                list = editYssbService.editEskt(nkYssbhjKt);
            }


        }else {
            if (nkYssbhjKt.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
                list = editYssbService.editYskts(nkYssbhjKt);
            }
            if (nkYssbhjKt.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_ES)){
                list = editYssbService.editEskts(nkYssbhjKt);
            }

        }
        return HttpResult.ok(list);
    }


    /**
     * 编辑-印刷
     */
    @AutoLog(value = "编辑合计印刷")
    @ApiOperation(value = "编辑合计印刷")
    @PostMapping(value = "/editYsys")
    public HttpResult<?> editYsys(@RequestBody NkYssbhjys nkYssbhjys){
        List list = new ArrayList();

        if (StringUtils.isNotBlank(nkYssbhjys.getId())) {

            NkYssbhjys oldnkYssbhjKt = nkYssbhjysServic.getById(nkYssbhjys.getId());
            NkYssbhyjl nkYssbhyjl = new NkYssbhyjl();
            nkYssbhyjl.setId(GetUuIdUtils.ReplaceUuId());
            if (StringUtils.isNotBlank(nkYssbhjys.getFlx())){
                nkYssbhyjl.setFlx(nkYssbhjys.getFlx());
            }else {
                throw new BusinessException("类型为空");
            }

            nkYssbhyjl.setFxgsj(DateConversionUtils.DateToYMDMM(new Date()));
            nkYssbhyjl.setFxgr(ThreadContextHelper.getCurrentUser().getName());
            nkYssbhyjl.setFxgrid(ThreadContextHelper.getCurrentUser().getId());
            nkYssbhyjl.setFxgrbm(ThreadContextHelper.getCurrentUser().getOrgName());
            nkYssbhyjl.setFsfbc(OaCommonFlowConstant.NO);
            nkYssbhyjl.setFyssbjhid(nkYssbhjys.getFyssbjhid());
            nkYssbhyjl.setFyssbhjid(nkYssbhjys.getId());
            //先判断传过来的字段
            if (StringUtils.isNotBlank(nkYssbhjys.getFsbmc())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjKt.getFsbmc());
                nkYssbhyjl.setFnewvalue(nkYssbhjys.getFsbmc());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjKt.getFks()+"书本名称:"+ oldnkYssbhjKt.getFsbmc()
                        + "为:" + nkYssbhjys.getFsbmc());
            }
            if (StringUtils.isNotBlank(nkYssbhjys.getFsbsl())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjKt.getFsbsl());
                nkYssbhyjl.setFnewvalue(nkYssbhjys.getFsbsl());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjKt.getFks()+"《"+oldnkYssbhjKt.getFsbmc()+"》"+"书本数量:"+ oldnkYssbhjKt.getFsbsl()
                        + "为:" + nkYssbhjys.getFsbsl());
            }
            if (StringUtils.isNotBlank(nkYssbhjys.getFmbqs())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjKt.getFmbqs());
                nkYssbhyjl.setFnewvalue(nkYssbhjys.getFmbqs());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjKt.getFks()+"《"+oldnkYssbhjKt.getFsbmc()+"》"+"每本钱数:"+ oldnkYssbhjKt.getFmbqs()
                        + "为:" + nkYssbhjys.getFmbqs());
            }
            nkYssbhyjlService.save(nkYssbhyjl);

            if (nkYssbhjys.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
                list = editYssbService.editYsys(nkYssbhjys);
            }


            if (nkYssbhjys.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_ES)){
                list = editYssbService.editYEsys(nkYssbhjys);
            }


        }else {
            if (nkYssbhjys.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
                list = editYssbService.editYsyss(nkYssbhjys);
            }
            if (nkYssbhjys.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_ES)){
                list = editYssbService.editEsyss(nkYssbhjys);
            }

        }
        return HttpResult.ok(list);
    }


    /**
     * 编辑-培训
     */
    @AutoLog(value = "编辑合计培训")
    @ApiOperation(value = "编辑合计培训")
    @PostMapping(value = "/editYspx")
    public HttpResult<?> editYspx(@RequestBody NkYssbhjPx nkYssbhjps){
        List list = new ArrayList();

        if (StringUtils.isNotBlank(nkYssbhjps.getId())) {

            NkYssbhjPx oldnkYssbhjpx = nkYssbhjpxService.getById(nkYssbhjps.getId());
            NkYssbhyjl nkYssbhyjl = new NkYssbhyjl();
            nkYssbhyjl.setId(GetUuIdUtils.ReplaceUuId());
            if (StringUtils.isNotBlank(nkYssbhjps.getFlx())){
                nkYssbhyjl.setFlx(nkYssbhjps.getFlx());
            }else {
                throw new BusinessException("类型为空");
            }

            nkYssbhyjl.setFxgsj(DateConversionUtils.DateToYMDMM(new Date()));
            nkYssbhyjl.setFxgr(ThreadContextHelper.getCurrentUser().getName());
            nkYssbhyjl.setFxgrid(ThreadContextHelper.getCurrentUser().getId());
            nkYssbhyjl.setFxgrbm(ThreadContextHelper.getCurrentUser().getOrgName());
            nkYssbhyjl.setFsfbc(OaCommonFlowConstant.NO);
            nkYssbhyjl.setFyssbjhid(nkYssbhjps.getFyssbjhid());
            nkYssbhyjl.setFyssbhjid(nkYssbhjps.getId());
            //先判断传过来的字段
            if (StringUtils.isNotBlank(nkYssbhjps.getFpxmc())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjpx.getFpxmc());
                nkYssbhyjl.setFnewvalue(nkYssbhjps.getFpxmc());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjpx.getFks()+"培训名称:"+ oldnkYssbhjpx.getFpxmc()
                        + "为:" + nkYssbhjps.getFpxmc());
            }
            if (StringUtils.isNotBlank(nkYssbhjps.getFpxrs())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjpx.getFpxrs());
                nkYssbhyjl.setFnewvalue(nkYssbhjps.getFpxrs());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjpx.getFks()+"培训名称:"+ oldnkYssbhjpx.getFpxmc()+"培训人数:"+ oldnkYssbhjpx.getFpxrs()
                        + "为:" + nkYssbhjps.getFpxrs());
            }
            if (StringUtils.isNotBlank(nkYssbhjps.getFpxts())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjpx.getFpxts());
                nkYssbhyjl.setFnewvalue(nkYssbhjps.getFpxts());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjpx.getFks()+"培训名称:"+ oldnkYssbhjpx.getFpxmc()+"培训天数:"+ oldnkYssbhjpx.getFpxts()
                        + "为:" + nkYssbhjps.getFpxts());
            }

            if (StringUtils.isNotBlank(nkYssbhjps.getFxst())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjpx.getFxst());
                nkYssbhyjl.setFnewvalue(nkYssbhjps.getFxst());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjpx.getFxst()+"培训名称:"+ oldnkYssbhjpx.getFpxmc()+"学时/天:"+ oldnkYssbhjpx.getFxst()
                        + "为:" + nkYssbhjps.getFxst());
            }

            if (StringUtils.isNotBlank(nkYssbhjps.getFzgxs())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjpx.getFzgxs());
                nkYssbhyjl.setFnewvalue(nkYssbhjps.getFzgxs());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjpx.getFzgxs()+"培训名称:"+ oldnkYssbhjpx.getFpxmc()+"正高学时:"+ oldnkYssbhjpx.getFzgxs()
                        + "为:" + nkYssbhjps.getFzgxs());
            }

            if (StringUtils.isNotBlank(nkYssbhjps.getFfgxs())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjpx.getFfgxs());
                nkYssbhyjl.setFnewvalue(nkYssbhjps.getFfgxs());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjpx.getFfgxs()+"培训名称:"+ oldnkYssbhjpx.getFpxmc()+"副高学时:"+ oldnkYssbhjpx.getFfgxs()
                        + "为:" + nkYssbhjps.getFfgxs());
            }


            if (StringUtils.isNotBlank(nkYssbhjps.getFpxnr())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjpx.getFpxnr());
                nkYssbhyjl.setFnewvalue(nkYssbhjps.getFpxnr());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjpx.getFpxnr()+"培训名称:"+ oldnkYssbhjpx.getFpxmc()+"培训内容:"+ oldnkYssbhjpx.getFpxnr()
                        + "为:" + nkYssbhjps.getFpxnr());
            }

            if (StringUtils.isNotBlank(nkYssbhjps.getFpxdx())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjpx.getFpxdx());
                nkYssbhyjl.setFnewvalue(nkYssbhjps.getFpxdx());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjpx.getFpxdx()+"培训名称:"+ oldnkYssbhjpx.getFpxmc()+"培训对象:"+ oldnkYssbhjpx.getFpxdx()
                        + "为:" + nkYssbhjps.getFpxdx());
            }

            if (StringUtils.isNotBlank(nkYssbhjps.getFpxdd())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjpx.getFpxdd());
                nkYssbhyjl.setFnewvalue(nkYssbhjps.getFpxdd());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjpx.getFpxdd()+"培训名称:"+ oldnkYssbhjpx.getFpxmc()+"培训地点:"+ oldnkYssbhjpx.getFpxdd()
                        + "为:" + nkYssbhjps.getFpxdd());
            }

            if (StringUtils.isNotBlank(nkYssbhjps.getFpxbz())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjpx.getFpxbz());
                nkYssbhyjl.setFnewvalue(nkYssbhjps.getFpxbz());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjpx.getFpxbz()+"培训名称:"+ oldnkYssbhjpx.getFpxmc()+"培训备注:"+ oldnkYssbhjpx.getFpxbz()
                        + "为:" + nkYssbhjps.getFpxbz());
            }




            nkYssbhyjlService.save(nkYssbhyjl);

            if (nkYssbhjps.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
                list = editYssbService.editYspx(nkYssbhjps);
            }


            if (nkYssbhjps.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_ES)){
                list = editYssbService.editEspx(nkYssbhjps);
            }


        }else {
            if (nkYssbhjps.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
            list = editYssbService.editYspxs(nkYssbhjps);
        }
        if (nkYssbhjps.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_ES)){
            list = editYssbService.editEspxs(nkYssbhjps);
        }

    }
        return HttpResult.ok(list);
    }

    /**
     * 编辑-绩效指标合计
     */
    @AutoLog(value = "编辑绩效指标合计")
    @ApiOperation(value = "编辑绩效指标合计")
    @PostMapping(value = "/editYssbjxbz")
    public HttpResult<?> editYssbjxbz(@RequestBody NkYssbhjjxzb nkYssbhjjxzb){
        List list = new ArrayList();

        if (StringUtils.isNotBlank(nkYssbhjjxzb.getId())) {

            NkYssbhjjxzb oldnkYssbhjjxzb = nkYssbhjjxzbService.getById(nkYssbhjjxzb.getId());
            NkYssbhyjl nkYssbhyjl = new NkYssbhyjl();
            nkYssbhyjl.setId(GetUuIdUtils.ReplaceUuId());
            if (StringUtils.isNotBlank(nkYssbhjjxzb.getFlx())){
                nkYssbhyjl.setFlx(nkYssbhjjxzb.getFlx());
            }else {
                throw new BusinessException("类型为空");
            }

            nkYssbhyjl.setFxgsj(DateConversionUtils.DateToYMDMM(new Date()));
            nkYssbhyjl.setFxgr(ThreadContextHelper.getCurrentUser().getName());
            nkYssbhyjl.setFxgrid(ThreadContextHelper.getCurrentUser().getId());
            nkYssbhyjl.setFxgrbm(ThreadContextHelper.getCurrentUser().getOrgName());
            nkYssbhyjl.setFsfbc(OaCommonFlowConstant.NO);
            nkYssbhyjl.setFyssbjhid(oldnkYssbhjjxzb.getFjhid());
            nkYssbhyjl.setFyssbhjid(nkYssbhjjxzb.getId());
            //先判断传过来的字段
            if (StringUtils.isNotBlank(nkYssbhjjxzb.getFsjzb())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjjxzb.getFsjzb());
                nkYssbhyjl.setFnewvalue(nkYssbhjjxzb.getFsjzb());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjjxzb.getFks()+oldnkYssbhjjxzb.getFyjzblx() + oldnkYssbhjjxzb.getFejzblx()+ oldnkYssbhjjxzb.getFsjzb()
                        + "为:" + nkYssbhjjxzb.getFsjzb());
            }
            if (StringUtils.isNotBlank(nkYssbhjjxzb.getFzbz())) {
                nkYssbhyjl.setFoldvalue(oldnkYssbhjjxzb.getFzbz());
                nkYssbhyjl.setFnewvalue(nkYssbhjjxzb.getFzbz());
                nkYssbhyjl.setFxgjl("修改" +oldnkYssbhjjxzb.getFks()+oldnkYssbhjjxzb.getFyjzblx() + oldnkYssbhjjxzb.getFejzblx()+ oldnkYssbhjjxzb.getFzbz()
                        + "为:" + nkYssbhjjxzb.getFzbz());
            }


            nkYssbhyjlService.save(nkYssbhyjl);

            if (nkYssbhjjxzb.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
                list = editYssbService.editYsjxhj(nkYssbhjjxzb);
            }


            if (nkYssbhjjxzb.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_ES)){
                list = editYssbService.editEsjxhj(nkYssbhjjxzb);
            }


        }else {
            if (nkYssbhjjxzb.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
                list = editYssbService.editYsjxhjs(nkYssbhjjxzb);
            }
            if (nkYssbhjjxzb.getFlx().equals(OaFlowConstant.YSSBLC_CWSH_ES)){
                list = editYssbService.editEsjxhjs(nkYssbhjjxzb);
            }

        }
        return HttpResult.ok(list);

    }



//    /**
//     * 删除会议记录
//     */
//    @AutoLog(value = "删除会议记录")
//    @ApiOperation(value = "删除会议记录")
//    @GetMapping(value = "/dehyjl")
//    public HttpResult<?> dehyjl(String jhid,String sfbc) {
//        if (sfbc.equals(OaCommonFlowConstant.NO)){
//            List<NkYssbhyjl> yssbhyjls = nkYssbhyjlService.list(new LambdaQueryWrapper<NkYssbhyjl>()
//                    .eq(NkYssbhyjl::getFyssbjhid, jhid));
//            nkYssbhyjlService.removeBatchByIds(yssbhyjls);
//        }else {
//            List<NkYssbhyjl> yssbhyjls = nkYssbhyjlService.list(new LambdaQueryWrapper<NkYssbhyjl>()
//                    .eq(NkYssbhyjl::getFyssbjhid, jhid));
//            for (NkYssbhyjl yssbhyjl : yssbhyjls){
//                yssbhyjl.setFsfbc(OaCommonFlowConstant.YES);
//            }
//            nkYssbhyjlService.updateBatchById(yssbhyjls);
//        }
//        return HttpResult.ok("成功");
//
//    }

//    /**
//     * 会议记录列表
//     */
//    @AutoLog(value = "差旅劳务会议记录列表")
//    @ApiOperation(value = "差旅劳务会议记录列表")
//    @GetMapping(value = "/hyjlList")
//    public HttpResult<?> hyjlList(String jhid,String flx) {
//        List<NkYssbhyjl> yssbhyjls = nkYssbhyjlService.list(new LambdaQueryWrapper<NkYssbhyjl>()
//                .eq(NkYssbhyjl::getFyssbjhid, jhid)
//                .eq(NkYssbhyjl::getFlx, flx)
//                .orderByAsc(NkYssbhyjl :: getCreateTime));
//
//        if (CollectionUtils.isNotEmpty(yssbhyjls)){
//            return HttpResult.ok(yssbhyjls);
//        }else {
//            return HttpResult.ok(yssbhyjls);
//        }
//    }



    /**
     * 流程列表分页查询
     * @param
     * @param pageNo
     * @param pageSize
     * @param onlyCurrentUser
     * @return
     */
    @AutoLog(value = "流程监控-分页查询")
    @ApiOperation(value = "流程监控-分页查询")
    @GetMapping("flowJkPage")
    public HttpResult flowJkPage(
            NkysxmsplcVo nkysxmsplcVo,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        nkysxmsplcVo.setFlcmc(OaFlowConstant.NK_YSSBLC_NAME);
        Page<NkysxmsplcVo> page = new Page<>(pageNo, pageSize);

        IPage<NkysxmsplcVo> list = null;
        if (StringUtils.isNotBlank(nkysxmsplcVo.getOaid())){
            NkBmysxmsbsplc nkBmysxmsbsplc = nkyssbbsplcService.getById(nkysxmsplcVo.getOaid());
            if (nkBmysxmsbsplc != null){
                list = nkyssbbsplcFlowMapper.flowJkPage(page,onlyCurrentUser,user,nkysxmsplcVo);
            }
        }
        return HttpResult.ok(list);
    }

    /**
     * 流程列表分页查询
     * @param
     * @param pageNo
     * @param pageSize
     * @param onlyCurrentUser
     * @return
     */
    @AutoLog(value = "流程列表-分页查询")
    @ApiOperation(value = "流程列表-分页查询")
    @GetMapping("flowJobPage")
    public HttpResult<?> flowJobPage(
            NkysxmsplcVo nkysxmsplcVo,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        nkysxmsplcVo.setFlcmc(OaFlowConstant.NK_YSSBLC_NAME);
        if (StringUtils.isBlank(nkysxmsplcVo.getFblzt())) {
            nkysxmsplcVo.setFblzt(OaCommonFlowConstant.BLZT_DB);
        }
        Page<NkysxmsplcVo> page = new Page<>(pageNo, pageSize);
        IPage<NkysxmsplcVo> list = nkyssbbsplcFlowMapper.flowJobPage(page, onlyCurrentUser, user, nkysxmsplcVo);
        return HttpResult.ok(list);
    }


    /**
     * 我的已办
     */
    @AutoLog(value = "流程列表-我的已办")
    @ApiOperation(value = "流程列表-我的已办")
    @GetMapping("myJobPage")
    public HttpResult<?> myJobPage(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            NkysxmsplcVo nkysxmsplcVo) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        Page<NkysxmsplcVo> page = new Page<>(pageNo, pageSize);
        IPage<NkysxmsplcVo> list = nkyssbbsplcFlowMapper.myYbFlowPage(page, true, user, nkysxmsplcVo);
        return HttpResult.ok(list);
    }


    /**
     * 数据修订
     */
    @AutoLog(value = "列表-数据修订")
    @ApiOperation(value = "列表-数据修订")
    @GetMapping("Pagesjxd")
    public HttpResult<?> Pagesjxd(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            NkysxmsplcVo nkysxmsplcVo) {

        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }

        Page<NkysxmsplcVo> page = new Page<>(pageNo, pageSize);
        IPage<NkysxmsplcVo> list = nkyssbbsplcFlowMapper.myYbFlowPage(page, false, user, nkysxmsplcVo);
        return HttpResult.ok(list);
    }






    @AutoLog(value = "发起部门预算申报流程")
    @ApiOperation(value = "发起部门预算申报流程")
    @PostMapping(value = "initBzFlow")
    public HttpResult<?> initBzFlow(@RequestBody NkBmysxmsbsplc nkBmysxmsbsplc) {

        String oaid = "";
        //当前人的id
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        if (currentUser == null) {
            return HttpResult.error("当前登录已失效，请重新登录");
        }
        if (StringUtils.isNotBlank(nkBmysxmsbsplc.getId())){
            NkBmysxmsbsplc nkbmysxmsbsplc =  nkyssbbsplcService.getById(nkBmysxmsbsplc.getId());

            ConvertUtils.register(new DateConvert(), Date.class);
            try {
                BeanUtils.populate(nkbmysxmsbsplc, BeanUtils.describe(nkBmysxmsbsplc));
            } catch (IllegalAccessException e) {
                log.error("出错-保存事项【非法访问异常】,{}", e.getMessage());
            } catch (InvocationTargetException e) {
                log.error("出错-保存事项【调用TargetException】,{}", e.getMessage());
            } catch (NoSuchMethodException e) {
                log.error("出错-找不到可用方法", e.getMessage());
            }
            oaid = nkBmysxmsbsplc.getId();
            nkbmysxmsbsplc.setFfqr(currentUser.getName());
            nkbmysxmsbsplc.setFfqrid(currentUser.getId());
            nkbmysxmsbsplc.setFfqrbm(currentUser.getOrgName());

            List<NkRsnd> nkRsnds = nkRsNdService.list(new LambdaQueryWrapper<NkRsnd>()
                    .eq(NkRsnd::getFsfxz, OaCommonFlowConstant.NDXZ_YES));

            int ndi = Integer.valueOf(nkRsnds.get(0).getFnd()) + 1;
            //如果本年度的计划为空，新建计划.然后更新

            String nd = String.valueOf(ndi);


            nkbmysxmsbsplc.setFnd(nd);
            nkbmysxmsbsplc.setFjhsj(DateConversionUtils.DateToStringYYYYMMDD(new Date()));

            // Date日期单独做处理
            nkyssbbsplcService.updateById(nkbmysxmsbsplc);
        }else {
            oaid = GetUuIdUtils.ReplaceUuId();
            nkBmysxmsbsplc.setId(oaid);
            nkBmysxmsbsplc.setFfqr(currentUser.getName());
            nkBmysxmsbsplc.setFfqrid(currentUser.getId());
            nkBmysxmsbsplc.setFfqrbm(currentUser.getOrgName());
            nkBmysxmsbsplc.setFjhsj(DateConversionUtils.DateToStringYYYYMMDD(new Date()));
            nkyssbbsplcService.save(nkBmysxmsbsplc);
        }

        /**
         * @Author: lhb
         * @Description : 是否发起流程   如果是开始申请就跳转流程
         *               在这里设置  指定下个环节节点 做当前跳转流程的判断，然后设置变量接收环节的值，写到nextNodeName中
         * @DateTime:
         * @Params: Fsffqlc
         */
        String msg = "保存成功";
        String lcmbCode = OaFlowConstant.NK_YSSBLC;

        OaJobEntity job = new OaJobEntity();
        // 初始化流程
        Result result = nkyssbFlowService.createProcess(lcmbCode,oaid, currentUser);
        //做一次规则校验 如果查到此oaid 在表中已经插入 那就执行更新
        NkBmysxmsbsplc nkBmysxmsbsplc1 = nkyssbbsplcService.getById(oaid);
        List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        String bt = currentUser.getName()+"提交的预算申报计划"; //标题
        String zy = "计划时间:["+ nkBmysxmsbsplc1.getFjhsj() +"]"+"\n";
        if (oaProcessBusinessList.size() == 0){
            //初始化的时候 像 流程业务主表添加拼接初始化数据
            oaProcessBusinessService.addProcess(oaid,zy,bt,lcmbCode,OaFlowConstant.NK);

        }else {
            String id = oaProcessBusinessList.get(0).getId();  //当前已经插入的主键id 然后更新 摘要信息
            OaProcessBusiness oaProcessBusiness = oaProcessBusinessService.getById(id);
            oaProcessBusiness.setFzy(zy);
            oaProcessBusinessService.updateById(oaProcessBusiness);

        }

        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }else {
            job = (OaJobEntity) result.getResult();
            if (job != null) {
                // 是否提交流程
                if(StringUtils.isBlank(oaid)){
                    return HttpResult.error("参数丢失");
                }
                String nextNodeId = "";
                String nextNodeDbrId = "";
                if (StringUtils.isNotBlank(nkBmysxmsbsplc.getFsffqlc()) && nkBmysxmsbsplc.getFsffqlc().equals(OaCommonFlowConstant.SFFQLC_YES)) {
                    //使用流程编码查询流程模板


                    if (StringUtils.isBlank(nkBmysxmsbsplc.getFlczt())) {
                        nkBmysxmsbsplc.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
                    }
                    Result result1 = nkyssbFlowService.passJob(oaid,job.getId(),"同意", nextNodeId, nextNodeDbrId);
                    if (!result1.isSuccess()) {
                        return HttpResult.error(result.getMessage());
                    }
                    msg = "提交成功";
                    //提交完成后 更新通知信息
                    oaSysTzMessageService.tjMessage(oaid);

                    List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                            .eq(OaProcessBusiness::getFpid, oaid));
                    OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
                    OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
                    byId1.setFsfkch(0);
                    OaJobEntity oaJob = oaSpcySqsxJobService.getById(job);
                    if (oaJob.getFhjmc().equals(OaFlowConstant.CCSP_HJMC_ZXLDSH)) {
                        byId1.setFsfkbx(OaFlowConstant.QXJ_YES);
                    }

                    byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
                    oaProcessBusinessService.updateById(byId1);

                    myLcFlowService.recall(oaid);
                }
            }
        }

        HashMap map = new HashMap();
        map.put("msg",msg);
        map.put("nkMap",nkBmysxmsbsplc);
        map.put("jobMap",job);

        return HttpResult.ok(map);
    }

    /**
     * 内控-部门预算申报保存接口
     */
    @AutoLog(value = "内控-部门预算申报保存接口")
    @ApiOperation(value = "内控-部门预算申报保存接口")
    @PostMapping(value = "/saveFlow")
    public HttpResult<?> saveFlow(@RequestBody OaFlowVo oaFlowVo) {
        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SAVE; // 保存

        String jobId = oaFlowVo.getJobid(); // 当前流程任务id
        String oaid = oaFlowVo.getOaid(); // 当前办公主键id
        String opinion = oaFlowVo.getOpinion(); // 办理意见

        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.NK_YSSBLC);
        }
        if (StringUtils.isBlank(jobId)){
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        // 流程处理
        Result httpResult = nkyssbFlowService.handleFlow(oaFlowVo, null, jobId, oaid, submitType, opinion);
        if (!httpResult.isSuccess()){
            return HttpResult.error(httpResult.getMessage());
        }
        Map map = new HashMap();
        HttpResult<Object> res = new HttpResult<>(true);
        res.setMessage("保存成功");
        res.setResult(map);
        return res;
    }


    @AutoLog(value = "内控-部门预算申报提交接口")
    @ApiOperation(value = "内控-部门预算申报提交接口")
    @PostMapping(value = "/submitFlow")
    public HttpResult<?> submitFlow(@RequestBody OaFlowVo oaFlowVo) {

        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SUBMIT; // 提交
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        String jobId = oaFlowVo.getJobid();




        String oaid = oaFlowVo.getOaid();
        String opinion = oaFlowVo.getOpinion();
        NkBmysxmsbsplc oaId = nkyssbbsplcService.getById(oaid);
        OaJobEntity job = oaSpcySqsxJobService.getById(jobId);

        if (job.getFdbrid() != null && !job.getFdbrid().isEmpty()) {
            // 检查id是否在逗号分隔的字符串中
            boolean contains = job.getFdbrid().contains(currentUser.getId());
            if (!contains){
                throw new BusinessException("您没有权限提交该流程");
            }
        }
        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.NK_YSSBLC);
        }

        if (job.getFhjmc().equals(OaFlowConstant.YSSBLC_CWSH_YS)){
            //重新获取摘要信息
            NkBmysxmsbsplc nkRsBmysxmsb = nkyssbbsplcService.getById(oaid);


            List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                    .eq(OaProcessBusiness::getFpid, oaid));
            String zy = "";
            String bt = currentUser.getName()+"提交的预算申报计划"; //标题
            if (StringUtils.isNotBlank(nkRsBmysxmsb.getFjhsj())){
                zy =  "申请日期:["+ nkRsBmysxmsb.getFjhsj() +"]"+"\n";
            }else {
                zy =  "申请日期:["+ DateConversionUtils.DateToStringYYYYMMDD(new Date()) +"]"+"\n";
            }

            if (oaProcessBusinessList.size() == 0){
                //初始化的时候 像 流程业务主表添加拼接初始化数据
                oaProcessBusinessService.addProcess(oaid,zy,bt,"NK_YSSBLC",OaFlowConstant.NK);

            }else {
                String id = oaProcessBusinessList.get(0).getId();  //当前已经插入的主键id 然后更新 摘要信息
                OaProcessBusiness oaProcessBusiness = oaProcessBusinessService.getById(id);
                oaProcessBusiness.setFzy(zy);
                oaProcessBusinessService.updateById(oaProcessBusiness);

            }

        }else if (job.getFhjmc().equals(OaFlowConstant.YSSBLC_ZXZRSH_ES)) {

        } else {
            oaId.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
        }
        if (StringUtils.isBlank(oaId.getFsffqlc())) {
            oaId.setFsffqlc(OaCommonFlowConstant.SFFQLC_YES);
        }

        nkyssbbsplcService.updateById(oaId);

        if (StringUtils.isBlank(jobId)) {
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        /* if (StringUtils.isBlank(opinion)){
            return HttpResult.error("请填写办理意见");2
        }*/

        OaJobEntity nowJob = null;
        Result httpResult1 = nkyssbFlowService.handleFlow(oaFlowVo, nowJob, jobId, oaid, submitType, opinion);
        if (!httpResult1.isSuccess()){
            return HttpResult.error(httpResult1.getMessage());
        }
        List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
        OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
        byId1.setFsfkch(0);

        if (job.getFhjmc().equals(OaFlowConstant.CCSP_HJMC_ZXLDSH)) {
            byId1.setFsfkbx(OaFlowConstant.QXJ_YES);
        }

        byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
        oaProcessBusinessService.updateById(byId1);

        //提交完成后 更新待办信息
        oaSysTzMessageService.tjMessage(oaid);
        myLcFlowService.recall(oaid);


        return HttpResult.ok("提交成功");
    }





    /**
     * 批量查询
     */
    @AutoLog(value = "批量查询")
    @ApiOperation(value = "批量查询")
    @ApiImplicitParam(value = "jobids", name = "jobids", required = true)
    @GetMapping(value = "queryBatchJobByJobIds")
    public HttpResult<?> queryBatchJobByJobIds(@RequestParam("jobids")String jobids) {
        if (StringUtils.isBlank(jobids)) {
            return HttpResult.error("参数不能为空,请选择数据");
        }
        List<Map> mapList = new ArrayList<>();
        List<String> jobidsList = Arrays.asList(jobids.split(","));
        if (CollectionUtils.isNotEmpty(jobidsList)) {
            for (String jobid : jobidsList){
                mapList.add(nkyssbFlowService.getJobConcernByJobId(jobid));
            }
        }
        return HttpResult.ok(mapList);
    }

    /**
     * 查询当前流程任务详情-通过当前流程任务id
     */
    @AutoLog(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiOperation(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiImplicitParam(value = "jobid", name = "流程任务id", required = true)
    @GetMapping(value = "queryJobByJobId")
    public HttpResult<?> queryJobByJobId(@RequestParam("jobid") String jobid) {
        if (StringUtils.isBlank(jobid)) {
            return HttpResult.error("流程任务id不能为空");
        }
        Map map = nkyssbFlowService.getJobConcernByJobId(jobid);
        return HttpResult.ok(map);
    }

    /**
     * 获取已办列表-通过当前流程id-自定义退回
     *
     * @param jobid
     * @return
     */
    @AutoLog(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiOperation(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobid", value = "流程任务id"),
            @ApiImplicitParam(name = "isZdhj", value = "是否指定环节，默认：true，指定")
    })
    @GetMapping(value = "queryAllYbJob")
    public HttpResult<?> queryAllYbJob(@RequestParam(value = "jobid", defaultValue = "") String jobid,
                                       @RequestParam(value = "isZdhj", defaultValue = "true") boolean isZdhj) {
        List<Map<String, String>> currentJobPrevious = nkyssbFlowService.getCurrentJobPrevious(jobid, isZdhj);
        return HttpResult.ok(currentJobPrevious);
    }

    /**
     * 退回环节
     *
     * @return
     */
    @AutoLog(value = "自定义-退回环节")
    @ApiOperation(value = "自定义-退回环节")
    @PostMapping(value = "returnUpperzdyFlowJob")
    public HttpResult<?> returnUpperzdyFlowJob(@RequestBody OaReturnVo oaReturnVo) {
        nkyssbFlowService.returnZdJob(oaReturnVo);

        //退回更新通知信息
        OaJobEntity oaJob = oaSpcySqsxJobService.getById(oaReturnVo.getJobid());
        String fpid = oaJob.getFpid();
        oaSysTzMessageService.endMessage(fpid,false,false,true);

        return HttpResult.ok("退回成功");
    }

    @AutoLog(value = "删除预算申报计划")
    @ApiOperation(value = "删除部门预算申报计划")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobids",value = "流程任务id,逗号分割",required = true)
    })
    @DeleteMapping(value = "deleteFlowJob")
    public HttpResult<?> deleteFlowJob(@RequestParam(value = "jobids") String jobids){
        if (StringUtils.isBlank(jobids)){
            return HttpResult.error("参数不能为空");
        }
        List<String> jobIdList = Arrays.asList(jobids.split(","));
        String logNr = "";
        Map<String, Object> map = new HashMap<>();
        if (CollectionUtils.isNotEmpty(jobIdList)){
            List<OaJobEntity> jobList = oaSpcySqsxJobService.listByIds(jobIdList);
            if (CollectionUtils.isNotEmpty(jobList)){
                for (OaJobEntity job : jobList) {
                    oaSpcySqsxJobService.removeById(job.getId());
                    NkBmysxmsbsplc nkRsYstpsq = nkyssbbsplcService.getById(job.getFpid());
                    if (nkRsYstpsq != null) {
                        nkyssbbsplcService.removeById(job.getFpid());

                        logNr = "删除预算申报计划" + job.getFhjmc() + ": ";
                        map = ObjectToMapUtils.objectToMap(nkRsYstpsq);
                        logNr += LogUtils.MapToStringMethod(map);

                        spcyLogService.addLogs(job.getFhjmc(), logNr, job.getFpid(), OaFlowConstant.NK_YSSBLC, OaCommonFlowConstant.LOGS_SYS_TYPE_SC);
                    }
                }
            }
        }

        return HttpResult.ok("删除成功");
    }






    /**
     * 根据年度获取当前预算申报流程环节节点
     */
    @AutoLog(value = "根据年度获取当前预算申报流程环节节点")
    @ApiOperation(value = "根据年度获取当前预算申报流程环节节点")

    @GetMapping(value = "gethjjdBynd")
    public HttpResult<?> gethjjdBynd(){

        List<NkRsnd> nkRsnds = nkRsNdService.list(new LambdaQueryWrapper<NkRsnd>()
                .eq(NkRsnd::getFsfxz, OaCommonFlowConstant.NDXZ_YES));

        int ndi = Integer.valueOf(nkRsnds.get(0).getFnd()) + 1;
        //如果本年度的计划为空，新建计划.然后更新

        String nd = String.valueOf(ndi);



        List<NkBmysxmsbsplc> nkBmysxmsbsplcs = new ArrayList<>();
        String fhjmc = "";
        if (StringUtils.isBlank(nd)){
             nkBmysxmsbsplcs = nkyssbbsplcService.list(new LambdaQueryWrapper<NkBmysxmsbsplc>()
                    .eq(NkBmysxmsbsplc::getFnd, DateConversionUtils.DateToYear(new Date())));
        }else {
             nkBmysxmsbsplcs = nkyssbbsplcService.list(new LambdaQueryWrapper<NkBmysxmsbsplc>()
                    .eq(NkBmysxmsbsplc::getFnd, nd));
        }
        if (CollectionUtils.isNotEmpty(nkBmysxmsbsplcs)){
            String id = nkBmysxmsbsplcs.get(0).getId();
            List<OaJobEntity> jobEntities = oaSpcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                    .eq(OaJobEntity::getFpid, id));
            if (CollectionUtils.isNotEmpty(jobEntities)){
                //判断这个list中的数据是否含有待办的字样
                List<OaJobEntity> collect = jobEntities.stream().filter(w -> w.getFblzt().equals(OaCommonFlowConstant.BLZT_DB)).collect(Collectors.toList());
                //如果有待办那就返回这个待办的环节名称。如果没有待办，那就返回 流程结束

                if (CollectionUtils.isNotEmpty(collect)){
                    fhjmc = collect.get(0).getFhjmc();
                }else {
                    fhjmc = OaCommonFlowConstant.FLOW_LCJS;
                }
            }else {
                fhjmc = OaCommonFlowConstant.FLOW_LCWB;
            }

        }
        return HttpResult.ok(fhjmc);



    }


    /**
     * 预算申报打印获取数据
     */
    @AutoLog(value = "预算申报打印获取数据")
    @ApiOperation(value = "预算申报打印获取数据")
    @GetMapping(value = "/getYssbPrintData")
    public HttpResult<?> getYssbPrintData(String jhid,String flx){
        //检查 差旅费
        String fclfhjh = "0";
        //检查 劳务费
        String flwf = "0";
        BigDecimal fclfhjhs = new BigDecimal(fclfhjh);
        BigDecimal flwfs = new BigDecimal(flwf);
        //检查
        List<NkYssbhj> nkYssbhjs = nkYssbhjService.list(new LambdaQueryWrapper<NkYssbhj>()
                .eq(NkYssbhj::getFyssbjhid, jhid)
                .eq(NkYssbhj::getFlx, flx));
        for (NkYssbhj nkYssbhj : nkYssbhjs){
            fclfhjhs =fclfhjhs.add(new BigDecimal(Optional.ofNullable(nkYssbhj.getFclfhjh()).orElseGet(() -> "0")));
            flwfs = flwfs.add(new BigDecimal(Optional.ofNullable(nkYssbhj.getFlwfxj()).orElseGet(() -> "0")));
        }

        //课题 课题数
        String fkts = "0";
        //课题 课题经费
        String fktjf = "0";

        BigDecimal fktjfs = new BigDecimal(fktjf);
        BigDecimal fktss = new BigDecimal(fkts);

        List<NkYssbhjKt> yssbhjKts = nkYssbhjKtService.list(new LambdaQueryWrapper<NkYssbhjKt>()
                .eq(NkYssbhjKt::getFyssbjhid, jhid)
                .eq(NkYssbhjKt::getFlx, flx));

        for (NkYssbhjKt nkYssbhjKt : yssbhjKts){
            fktjfs = fktjfs.add(new BigDecimal(Optional.ofNullable(nkYssbhjKt.getFktjf()).orElseGet(() -> "0")));
        }
        int size = yssbhjKts.size();
        fktss = new BigDecimal(size);


        //印刷 印刷数
        String fysxs = "0";
        //印刷 印刷费
        String fysxf = "0";

        BigDecimal fysxss = new BigDecimal(fysxs);
        BigDecimal fysxfs = new BigDecimal(fysxf);

        List<NkYssbhjys> nkYssbhjys = nkYssbhjysServic.list(new LambdaQueryWrapper<NkYssbhjys>()
                .eq(NkYssbhjys::getFyssbjhid, jhid)
                .eq(NkYssbhjys::getFlx, flx));
        for (NkYssbhjys nkYssbhjy : nkYssbhjys){
            fysxss = fysxss.add(new BigDecimal(Optional.ofNullable(nkYssbhjy.getFsbsl()).orElseGet(() -> "0")));
            fysxfs = fysxfs.add(new BigDecimal(Optional.ofNullable(nkYssbhjy.getFyzhj()).orElseGet(() -> "0")));
        }


        //培训 培训人数
        String fpxrs = "0";
        //培训 培训费
        String fpxf = "0";

        BigDecimal fpxrss = new BigDecimal(fpxrs);
        BigDecimal fpxfs = new BigDecimal(fpxf);

        List<NkYssbhjPx> nkYssbhjPxes = nkYssbhjpxService.list(new LambdaQueryWrapper<NkYssbhjPx>()
                .eq(NkYssbhjPx::getFyssbjhid, jhid)
                .eq(NkYssbhjPx::getFlx, flx));

        for (NkYssbhjPx nkYssbhjPx : nkYssbhjPxes){
            fpxrss = fpxrss.add(new BigDecimal(Optional.ofNullable(nkYssbhjPx.getFpxrs()).orElseGet(() -> "0")));
            fpxfs =  fpxfs.add(new BigDecimal(Optional.ofNullable(nkYssbhjPx.getFpxskxj()).orElseGet(() -> "0")));
        }
        HashMap map = new HashMap();
        map.put("clf", fclfhjhs);
        map.put("lwf", flwfs);
        map.put("kts", fktss);
        map.put("ktjf", fktjfs);
        map.put("fyss", fysxss);
        map.put("fysf", fysxfs);
        map.put("fpxrs", fpxrss);
        map.put("fpxf", fpxfs);

        //将预算申报的数据也放入map中
        NkBmysxmsbsplc nkBmysxmsbsplc = nkyssbbsplcService.getById(jhid);



        List<OaJobEntity> jobEntities = oaSpcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                .eq(OaJobEntity::getFpid, jhid));
        if (CollectionUtils.isNotEmpty(jobEntities)){
            map.put("fjob", jobEntities);
        }

        map.put("yssblc", nkBmysxmsbsplc);


        return HttpResult.ok(map);

    }












}
